import java.util.List;

public class LongestCommonPrefix {

    public static String solution(String[] strs){
        if(strs==null||strs.length==0){
            return "";
        }
        String pre=strs[0];
        for (int i = 1; i <strs.length ; i++) {
            while (strs[i].indexOf(pre)!=0){
                pre=pre.substring(0,pre.length()-1);
            }
        }
        return pre;
    }

    public static void main(String[] args) {
        String[] strs=new String[]{"flower","flow","flight"};
        System.out.println(solution(strs));
    }
}
